<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Scholarship {
	private $CI;
	
	public function __construct() {
		$this->CI = &get_instance();
		$this->CI->load->model('Scholarship_Model', 'scholarshipmodel');
	}
	
	public function get_scholarship_history($username) {
		return $this->CI->scholarshipmodel->get_scholarship_history($username);
	}
	
	public function get_register_history($username) {
		return $this->CI->scholarshipmodel->get_register_history($username);
	}
	
	public function get_scholarship_history_for_sponsor($username, $sponsor) {
		return $this->CI->scholarshipmodel->get_scholarship_history_for_sponsor($username, $sponsor);
	}
	
	public function get_register_history_for_sponsor($username, $sponsor) {
		return $this->CI->scholarshipmodel->get_register_history_for_sponsor($username, $sponsor);
	}
	
	public function list_scholarship_by_sponsor($sponsor) {
		return $this->CI->scholarshipmodel->list_scholarship_by_sponsor($sponsor);
	}
	
	public function list_offered_scholarship($offset, $limit, $type, $name = '', $sponsor = '') {
		return $this->CI->scholarshipmodel->list_offered_scholarship($offset, $limit, $type, $name, $sponsor);
	}
	
	public function count_all_scholarship($type, $name = '', $sponsor = '') {
		return $this->CI->scholarshipmodel->count_all_scholarship($type, $name, $sponsor);
	}
	
	public function get_offered_scholarship($username, $offset, $limit) {
		return $this->CI->scholarshipmodel->get_offered_scholarship($username, $offset, $limit);
	}
	
	public function count_offered_scholarship($username) {
		return $this->CI->scholarshipmodel->count_offered_scholarship($username);
	}
	
	public function get_obtained_scholarship($username) {
		return $this->CI->scholarshipmodel->get_obtained_scholarship($username);
	}
	
	public function update_reception_status($statuses, $username) {
		if ($this->CI->authentication->is_allowed('EDIT_RECEPTION_STATUS')) {
			return $this->CI->scholarshipmodel->update_reception_status($statuses, $username);
		} else {
			$this->CI->session->set_flashdata('error', 'Role tidak boleh mengakses fitur ini.');
			return FALSE;
		}
	}
	
	public function update_reception_scholarship($id, $delivery) {
		if ($this->CI->authentication->is_allowed('EDIT_RECEPTION_STATUS')) {
			return $this->CI->scholarshipmodel->update_reception_scholarship($id, $delivery);
		} else {
			$this->CI->session->set_flashdata('error', 'Role tidak boleh mengakses fitur ini.');
			return FALSE;
		}
	}
	
	public function get_scholarship_by_id_and_status($id, $status) {
		return $this->CI->scholarshipmodel->get_scholarship_by_id_and_status($id, $status);
	}
	
	public function get_scholarship_id($sponsorid, $name, $periodstart, $periodend) {
		return $this->CI->scholarshipmodel->get_scholarship_id($sponsorid, $name, $periodstart, $periodend);
	}
	
	public function get_scholarship_by_id_and_username($id, $username) {
		return $this->CI->scholarshipmodel->get_scholarship_by_id_and_username($id, $username);
	}
	
	public function get_scholarship_by_id_username_and_status($id, $username) {
		return $this->CI->scholarshipmodel->get_scholarship_by_id_username_and_status($id, $username);
	}
	
	public function get_required_file($id) {
		return $this->CI->scholarshipmodel->get_required_file($id);
	}
	
	public function get_provided_scholarship($sponsor, $offset, $limit, $type) {
		return $this->CI->scholarshipmodel->get_provided_scholarship($sponsor, $offset, $limit, $type);
	}
	
	public function count_provided_scholarship($sponsor, $type) {
		return $this->CI->scholarshipmodel->count_provided_scholarship($sponsor, $type);
	}
	
	public function get_scholarship_by_id_and_sponsor($id, $sponsor) {
		return $this->CI->scholarshipmodel->get_scholarship_by_id_and_sponsor($id, $sponsor);
	}
	
	public function get_reciever_scholarship($id, $offset, $limit, $type) {
		return $this->CI->scholarshipmodel->get_reciever_scholarship($id, $offset, $limit, $type);
	}
	
	public function count_reciever_scholarship($id, $status) {
		return $this->CI->scholarshipmodel->count_reciever_scholarship($id, $status);
	}
	
	public function apply_scholarship($id, $username) {
		if ($this->CI->authentication->is_allowed('APPLY_SCHOLARSHIP')) {
			return $this->CI->scholarshipmodel->apply_scholarship($id, $username);
		} else {
			$this->CI->session->set_flashdata('error', 'Role tidak boleh mengakses fitur ini.');
			return FALSE;
		}
	}
	
	public function get_document_by_scholarid_id_and_username($scholarid, $id, $username) {
		return $this->CI->scholarshipmodel->get_document_by_scholarid_id_and_username($scholarid, $id, $username);
	}
	
	public function get_sponsor() {
		return $this->CI->scholarshipmodel->get_sponsor();
	}
	
	public function add_scholarship($scholar) {
		if ($this->CI->authentication->is_allowed('CRUD_SCHOLARSHIP')) {
			return $this->CI->scholarshipmodel->add_scholarship($scholar);
		} else {
			$this->CI->session->set_flashdata('error', 'Role tidak boleh mengakses fitur ini.');
			return FALSE;
		}
	}
	
	public function edit_scholarship($id, $scholar) {
		if ($this->CI->authentication->is_allowed('CRUD_SCHOLARSHIP')) {
			return $this->CI->scholarshipmodel->edit_scholarship($id, $scholar);
		} else {
			$this->CI->session->set_flashdata('error', 'Role tidak boleh mengakses fitur ini.');
			return FALSE;
		}
	}
	
	public function get_selection_counter($id) {
		return $this->CI->scholarshipmodel->get_selection_counter($id);
	}
	
	public function get_delivery_status($id) {
		return $this->CI->scholarshipmodel->get_delivery_status($id);
	}
	
	public function search_invite_student($id, $offset, $limit, $name = '', $year = '', $major = '', $gpa = 0.00) {
		return $this->CI->scholarshipmodel->search_invite_student($id, $offset, $limit, $name, $year, $major, $gpa);
	}
	
	public function search_verify_student($id, $offset, $limit, $name = '', $year = '', $major = '') {
		return $this->CI->scholarshipmodel->search_verify_student($id, $offset, $limit, $name, $year, $major);
	}
	
	public function search_selection_student($id, $offset, $limit, $name = '', $year = '', $major = '', $gpa = 0.00) {
		return $this->CI->scholarshipmodel->search_selection_student($id, $offset, $limit, $name, $year, $major, $gpa);
	}
	
	public function search_recomend_student($id, $offset, $limit, $name = '', $year = '', $major = '', $gpa = 0.00) {
		return $this->CI->scholarshipmodel->search_recomend_student($id, $offset, $limit, $name, $year, $major, $gpa);
	}
	
	public function count_invite_student($id, $name = '', $year = '', $major = '', $gpa = 0.00) {
		return $this->CI->scholarshipmodel->count_invite_student($id, $name, $year, $major, $gpa);
	}
	
	public function count_verify_student($id, $name = '', $year = '', $major = '') {
		return $this->CI->scholarshipmodel->count_verify_student($id, $name, $year, $major);
	}
	
	public function count_selection_student($id, $name = '', $year = '', $major = '', $gpa = 0.00) {
		return $this->CI->scholarshipmodel->count_selection_student($id, $name, $year, $major, $gpa);
	}
	
	public function count_recomend_student($id, $name = '', $year = '', $major = '', $gpa = 0.00) {
		return $this->CI->scholarshipmodel->count_recomend_student($id, $name, $year, $major, $gpa);
	}
	
	public function update_status_applicant($id, $username, $status, $delete = FALSE) {
		if ($this->CI->authentication->is_allowed('CRUD_SCHOLARSHIP')) {
			return $this->CI->scholarshipmodel->update_status_applicant($id, $username, $status, $delete);
		} else {
			$this->CI->session->set_flashdata('error', 'Role tidak boleh mengakses fitur ini.');
			return FALSE;
		}
	}
	
	public function approve_applicant($id, $username, $status) {
		if ($this->CI->authentication->is_allowed('CRUD_SCHOLARSHIP')) {
			return $this->CI->scholarshipmodel->approve_applicant($id, $username, $status);
		} else {
			$this->CI->session->set_flashdata('error', 'Role tidak boleh mengakses fitur ini.');
			return FALSE;
		}
	}
	
	public function reject_applicant($id) {
		if ($this->CI->authentication->is_allowed('CRUD_SCHOLARSHIP')) {
			return $this->CI->scholarshipmodel->reject_applicant($id);
		} else {
			$this->CI->session->set_flashdata('error', 'Role tidak boleh mengakses fitur ini.');
			return FALSE;
		}
	}
	
	public function reject_registrant($id) {
		if ($this->CI->authentication->is_allowed('CRUD_SCHOLARSHIP')) {
			return $this->CI->scholarshipmodel->reject_registrant($id);
		} else {
			$this->CI->session->set_flashdata('error', 'Role tidak boleh mengakses fitur ini.');
			return FALSE;
		} 
	}
}